Step 10: DELETE Request
Let's include a route to delete a bookmark.
HTTP Method | DELETE |
---|---|
API Endpoint | /bookmarks/:id |
Request Path Parameter | id |
Request Query Parameter | |
Request Body | |
Response Body | JSON object (bookmark) |
Response Status | 200 |
Notice the path (endpoint) is similar to the GET request we had earlier for retrieving a bookmark given its ID. By convention, we return the deleted bookmark (with status code 200).
Update src/routes/bookmarks.js
to include the following route:
router.delete("/bookmarks/:id", (req, res) => {
const { id } = req.params;
const bookmark = bookmarkDao.delete(id);
res.json({
status: 200,
message: `Successfully deleted the following bookmark!`,
data: bookmark,
});
});
Save the code and commit the changes. Then, test this endpoint in Postman.